package com.bb.flow.service.imp.node.panduan;

import com.bb.flow.api.ConditionValueCalc;
import com.bb.flow.api.ExpressionCalc;
import com.bb.flow.api.entries.ConditionResult;
import com.bb.flow.api.entries.FlowContext;
import com.bb.flow.config.enumtype.DataType;

/**
 * @author bigbeard on 2018-11-16
 */
public class JudgeUserInput implements ConditionValueCalc, ExpressionCalc {


    /**
     * 结果条件条件判断
     *
     * @param flowNodeData  流程上下文参数
     * @return true:传入的条件成功,false:条件不成立
     */
    @Override
    public ConditionResult calcExpress( FlowContext flowNodeData) {
        ConditionResult result = new ConditionResult();
        result.setDataType(DataType.STRING);
        if (flowNodeData != null) {
            result.setResult("A");
        } else {
            result.setResult("B");
        }
        System.out.println("judge >>>>>" + this);
        return result;
    }

    /**
     * 计算表达式
     *
     * @param expression              表达式
     * @param flowNodeData            当前流程上下文信息
     * @param result 条件值结果
     * @return true 满足条件,false 不满足条件
     */
    @Override
    public boolean calc(
            String expression, FlowContext flowNodeData,
            ConditionResult result) {
        System.out.println(">>>>条件计算结果>>" + result + "<<<<" + expression);
        boolean x = (Math.random() * 100 > 50);
        System.out.println("judge>>>calc>>" + this + ">>result:" + x);
        return x;
    }
}
